package com.demo;

import com.demo.config.tus.TusDirectoryExpireCleaner;
import lombok.extern.slf4j.Slf4j;
import me.desair.tus.server.TusFileUploadService;
import org.noear.solon.Solon;
import org.noear.solon.SolonBuilder;
import org.noear.solon.core.Props;

import java.time.Duration;

@Slf4j
public class Application {


    public static void main(String[] args) {    //这是程序入口
        new SolonBuilder()
                .onError(e -> {
                    log.error("", e);
                })
                .start(Application.class, args, (app) -> {
                    final Props tusProperties = Solon.cfg().getProp("tus");
                    final TusFileUploadService tusFileUploadService = new TusFileUploadService();
                    tusFileUploadService.withStoragePath(tusProperties.get("chunkFilePath"));
                    if (tusProperties.getBool("enableClean",false)) {
                        tusFileUploadService.withUploadExpirationPeriod(Duration.parse(tusProperties.get("expireTime")).toMillis());
                    }


                    new Thread(new TusDirectoryExpireCleaner(tusProperties,tusFileUploadService)).start();
                });
    }


}